package uit.bus;

import android.app.Activity;
import android.content.SharedPreferences;
import android.location.Location;

import com.google.android.maps.GeoPoint;

public class SharedPrefren extends Activity {

	public SharedPreferences share;
	public static final String MODE_VIEW_KEY = "modeView";
	public static final String START_LAT_KEY = "startLat";
	public static final String START_LONG_KEY = "startLong";
	public static final String ZOOM_LEVEL_KEY = "zoomlevel";
	public static final String ITEM_BAT_DAU = "checkBD";
	public static final String ITEM_ZOOM = "checkZoom";
	public static final String TT_NHACNHO = "ttNhacNho";
	public static final String NHACNHO_LAT_KEY = "nnLat";
	public static final String NHACNHO_LONG_KEY = "nnLong";
	public static final String TEN_TRAM = "tentram";
	public static final String KC_NN = "kcnn";
	public static final String AMBAO = "ambao";
	public static final String LOTRINH = "lotrinh";
	public static final String DULICH1 = "dulich1";
	public static final String DULICH2 = "dulich2";
	public static final String DULICH3 = "dulich3";

	public SharedPrefren(SharedPreferences prefs) {
		super();
		share = prefs;
	}

	public int getModeView() {
		int modeView = share.getInt(MODE_VIEW_KEY, 0);
		return modeView;
	}

	public void setModeView(int modeView) {
		SharedPreferences.Editor editor = share.edit();
		editor.putInt(MODE_VIEW_KEY, modeView);
		editor.commit();
	}

	public void setStartPlace(GeoPoint point, boolean isCheck) {
		SharedPreferences.Editor editor = share.edit();
		if (isCheck) {
			editor.putInt(START_LAT_KEY, point.getLatitudeE6());
			editor.putInt(START_LONG_KEY, point.getLongitudeE6());
		} else {
			editor.putInt(START_LAT_KEY, 0);
			editor.putInt(START_LONG_KEY, 0);
		}
		editor.commit();
	}

	public GeoPoint getStartPlace() {
		int lati = 0, longi = 0;
		lati = share.getInt(START_LAT_KEY, 0);
		longi = share.getInt(START_LONG_KEY, 0);
		GeoPoint point = new GeoPoint(lati, longi);
		return point;
	}

	public void setItemBD(boolean ischeck) {
		SharedPreferences.Editor editor = share.edit();
		editor.putBoolean(ITEM_BAT_DAU, ischeck);
		editor.commit();
	}

	public boolean getStateBD() {
		boolean result = share.getBoolean(ITEM_BAT_DAU, false);
		return result;
	}

	public void setItemZoom(boolean ischeck) {
		SharedPreferences.Editor editor = share.edit();
		editor.putBoolean(ITEM_ZOOM, ischeck);
		editor.commit();
	}

	public boolean getStateZoom() {
		boolean result = share.getBoolean(ITEM_ZOOM, false);
		return result;
	}

	public void setZoomLevel(int zoom, boolean ischeck) {
		SharedPreferences.Editor editor = share.edit();
		if (ischeck) {
			editor.putInt(ZOOM_LEVEL_KEY, zoom);
		} else {
			editor.putInt(ZOOM_LEVEL_KEY, 0);
		}
		editor.commit();
	}

	public int getZoomLevel() {
		int zoom = share.getInt(ZOOM_LEVEL_KEY, 0);
		return zoom;
	}

	public void setNhacNho(boolean state) {
		SharedPreferences.Editor editor = share.edit();
		editor.putBoolean(TT_NHACNHO, state);
		editor.commit();
	}

	public boolean getNhacNho() {
		boolean result = share.getBoolean(TT_NHACNHO, false);
		return result;
	}

	public void setViTriNN(String lat, String longt) {
		SharedPreferences.Editor editor = share.edit();
		editor.putString(NHACNHO_LAT_KEY, lat);
		editor.putString(NHACNHO_LONG_KEY, longt);
		editor.commit();
	}

	public Location getViTriNN() {
		Location location = new Location("vitri");
		String slat = share.getString(NHACNHO_LAT_KEY, "0");
		String slongt = share.getString(NHACNHO_LONG_KEY, "0");
		location = new Location("NN");

		location.setLatitude(Double.valueOf(slat));
		location.setLongitude(Double.valueOf(slongt));
		return location;
	}

	public void setTenTram(String tentram) {
		SharedPreferences.Editor editor = share.edit();
		editor.putString(TEN_TRAM, tentram);
		editor.commit();
	}

	public String getTenTram() {
		return share.getString(TEN_TRAM, "");
	}

	public void setKCNN(int kc) {
		SharedPreferences.Editor editor = share.edit();
		editor.putInt(KC_NN, kc);
		editor.commit();
	}

	public int getKCNN() {
		return share.getInt(KC_NN, 0);
	}

	public void setAmBao(int ambao) {
		SharedPreferences.Editor editor = share.edit();
		editor.putInt(AMBAO, ambao);
		editor.commit();
	}

	public int getAmBao() {
		return share.getInt(AMBAO, 0);
	}

	public void setLoTrinh(int luot) {
		SharedPreferences.Editor editor = share.edit();
		editor.putInt(LOTRINH, luot);
		editor.commit();
	}

	public int getLoTrinh() {
		return share.getInt(LOTRINH, 0);
	}

	public void setTTDuLich1(boolean ischeck) {
		SharedPreferences.Editor editor = share.edit();
		editor.putBoolean(DULICH1, ischeck);
		editor.commit();
	}

	public void setTTDuLich2(boolean ischeck) {
		SharedPreferences.Editor editor = share.edit();
		editor.putBoolean(DULICH2, ischeck);
		editor.commit();
	}

	public void setTTDuLich3(boolean ischeck) {
		SharedPreferences.Editor editor = share.edit();
		editor.putBoolean(DULICH3, ischeck);
		editor.commit();
	}

	public boolean getTTDuLich1() {
		return share.getBoolean(DULICH1, false);
	}

	public boolean getTTDuLich2() {
		return share.getBoolean(DULICH2, false);
	}

	public boolean getTTDuLich3() {
		return share.getBoolean(DULICH3, false);
	}

	public boolean[] getListStatusDL() {
		boolean[] result = new boolean[3];
		result[0] = share.getBoolean(DULICH1, false);
		result[1] = share.getBoolean(DULICH2, false);
		result[2] = share.getBoolean(DULICH3, false);
		return result;
	}
}
